package com.ruoyi.system.service.impl;

import java.util.List;
import start.spring.basic.constant.CommonConstant;
import start.spring.basic.util.common.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.GgSysLogMapper;
import com.ruoyi.system.domain.GgSysLog;
import com.ruoyi.system.service.IGgSysLogService;

import com.ruoyi.system.service.BaseServiceImpl;

import start.spring.basic.page.PageQuery;
import start.spring.basic.page.PageResult;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 系统日志Service业务层处理
 * 
 * @author xuyy
 * @date 2023-06-25
 */
@Service
public class GgSysLogServiceImpl extends BaseServiceImpl implements IGgSysLogService {
    
    @Autowired
    private GgSysLogMapper ggSysLogMapper;

    /**
     * 查询系统日志列表
     * 
     * @param ggSysLog 系统日志
     * @return 系统日志
     */
    @Override
    public PageResult<GgSysLog> selectGgSysLogPageList(PageQuery pageQuery,GgSysLog ggSysLog) {
        IPage<GgSysLog> page = super.getPage(pageQuery);
        QueryWrapper<GgSysLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ggSysLog.getId()!=null, GgSysLog::getId, ggSysLog.getId());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggSysLog.getUserId()), GgSysLog::getUserId, ggSysLog.getUserId());
        queryWrapper.lambda().like(!StringUtil.isEmpty(ggSysLog.getUserName()), GgSysLog::getUserName, ggSysLog.getUserName());
        queryWrapper.lambda().like(!StringUtil.isEmpty(ggSysLog.getBizType()), GgSysLog::getBizType, ggSysLog.getBizType());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggSysLog.getTraceId()), GgSysLog::getTraceId, ggSysLog.getTraceId());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggSysLog.getSysCode()), GgSysLog::getSysCode, ggSysLog.getSysCode());
        if(!StringUtil.isEmpty(ggSysLog.getBeginStartTime()) && !StringUtil.isEmpty(ggSysLog.getEndStartTime())) {
        	queryWrapper.lambda().between(GgSysLog::getStartTime, ggSysLog.getBeginStartTime() + CommonConstant.SURFIX_DATE_BEGIN, ggSysLog.getEndStartTime() + CommonConstant.SURFIX_DATE_END);
        }
        queryWrapper.lambda().orderByDesc(GgSysLog::getStartTime);
        page = this.ggSysLogMapper.selectPage(page, queryWrapper);
        return super.getPageResult(page);
    }
    
    /**
     * 查询全量系统日志
     * 
     * @param ggSysLog 系统日志
     * @return 系统日志
     */
    @Override
    public List<GgSysLog> selectGgSysLogList(GgSysLog ggSysLog) {
        QueryWrapper<GgSysLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ggSysLog.getId()!=null, GgSysLog::getId, ggSysLog.getId());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggSysLog.getUserId()), GgSysLog::getUserId, ggSysLog.getUserId());
        queryWrapper.lambda().like(!StringUtil.isEmpty(ggSysLog.getUserName()), GgSysLog::getUserName, ggSysLog.getUserName());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggSysLog.getTraceId()), GgSysLog::getTraceId, ggSysLog.getTraceId());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggSysLog.getSysCode()), GgSysLog::getSysCode, ggSysLog.getSysCode());
        if(!StringUtil.isEmpty(ggSysLog.getBeginStartTime()) && !StringUtil.isEmpty(ggSysLog.getEndStartTime())) {
        	queryWrapper.lambda().between(GgSysLog::getStartTime, ggSysLog.getBeginStartTime() + CommonConstant.SURFIX_DATE_BEGIN, ggSysLog.getEndStartTime() + CommonConstant.SURFIX_DATE_END);
        }
        return this.ggSysLogMapper.selectList(queryWrapper);
    }

    /**
     * 新增系统日志
     * 
     * @param ggSysLog 系统日志
     * @return 结果
     */
    @Override
    public int insertGgSysLog(GgSysLog ggSysLog) {
        return this.ggSysLogMapper.insert(ggSysLog);
    }

    /**
     * 修改系统日志
     * 
     * @param ggSysLog 系统日志
     * @return 结果
     */
    @Override
    public int updateGgSysLog(GgSysLog ggSysLog) {
    	UpdateWrapper<GgSysLog> updateWrapper = new UpdateWrapper<>();
    	updateWrapper.lambda().eq(GgSysLog::getId, ggSysLog.getId());
        return this.ggSysLogMapper.update(ggSysLog, updateWrapper);
    }

    /**
     * 批量删除系统日志
     * 
     * @param ids 需要删除的系统日志主键
     * @return 结果
     */
    @Override
    public int deleteGgSysLogByIds(List<Long> ids) {
        return this.ggSysLogMapper.deleteBatchIds(ids);
    }
	
}
